﻿using UnityEngine.UI;
using UnityEngine;

[RequireComponent(typeof(BoxCollider2D))]
//提示牌,必须带有Canvas
public class Board : MonoBehaviour
{
    private GameObject obj_canvas;

    private void Awake()
    {
        Canvas canvas = GetComponentInChildren<Canvas>();
        if (canvas == null)
        {
            Destroy(this);
            return;
        }
        obj_canvas = canvas.gameObject;
        obj_canvas.SetActive(false);
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if(collision.GetComponent<Character>() != null)
        {
            obj_canvas.SetActive(true);
        }
    }

    private void OnTriggerExit2D(Collider2D collision)
    {
        if (collision.GetComponent<Character>() != null)
        {
            obj_canvas.SetActive(false);
        }
    }
}
